package com.jyh.aop01.service.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @author JYH
 * @version 1.0
 * @date 2022/11/11 15:42
 */
@Component
@Aspect
public class TransactionAop {
    @Pointcut("execution(* com.jyh.aop01.service.impl.*.*(..))")
    private void transationAdvice(){}

    @Before("transationAdvice()")
    public void before(){
        System.out.println("前置内容--开启事务");
    }

    @After("transationAdvice()")
    public void after(){
        System.out.println("后置内容--提交事务");
    }
    @AfterReturning("transationAdvice()")
    public void afterReturning(){
        System.out.println("后置返回通知");
    }
    @AfterThrowing("transationAdvice()")
    public void afterThrowing(){
        System.out.println("异常通知--事务回滚");
    }
    @Around("transationAdvice()")
    public void arount(ProceedingJoinPoint joinPoint) {
        System.out.println("环绕通知-前");
        try {
        joinPoint.proceed();//回调连接点方法
            System.out.println("方法执行完毕");
        } catch (Throwable throwable) {
            System.out.println("环绕通知-异常");
        }finally {
            System.out.println("环绕通知-最终");
        }
        }
    }
